package Java8实战.Lambda实战._2_Lambda方法引用_匿名类;

import Java8实战.Lambda实战.Apple;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;

public class _2_Lambda方法引用_匿名类 {
    public static void main(String[] args) {
        List<Apple> appleList = Arrays.asList(
                new Apple("red",150),
                new Apple("green",123),
                new Apple("green",450)
        );

        appleList.sort(new Comparator<Apple>() {
            @Override
            public int compare(Apple o1, Apple o2) {
                return o1.getWeight().compareTo(o2.getWeight());
            }
        });

        printByConsumer(appleList,(Apple apple) -> System.out.println("苹果的颜色：" + apple.getWeight() + "，苹果的重量：" + apple.getWeight()));


    }


    public static <T> void printByConsumer(List<T> list, Consumer<T> consumer){
        for (T t : list){
            consumer.accept(t);
        }
    }
}
